package com.imessage.action.device.client;

import com.bean.BusinessWuma;
import com.bean.DeviceClient;
import com.imessage.action.BaseAction;
import com.imessage.type.BusinessTaskCmd;
import com.imessage.type.DeviceClientState;
import com.imessage.vo.ClientVo;
import com.imessage.vo.WumaVo;
import io.ebean.Expr;
import io.ebean.Expression;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

public class ClientBaseAction extends BaseAction {

    protected final  String datagrid="datagrid-deviceClient-filter";

    protected void setExpressionList(List<Expression> expressionList, ClientVo clientVo){
        if(StringUtils.isNotBlank(clientVo.getName())){
            expressionList.add(Expr.contains("name", clientVo.getName()));
        }
        if(StringUtils.isNotBlank(clientVo.getState())){
            expressionList.add(Expr.eq("state", clientVo.getState()));
        }
        if(StringUtils.isNotBlank(clientVo.getTaskCmd())){
            expressionList.add(Expr.eq("taskCmd", clientVo.getTaskCmd()));
        }
    }

    protected void setModelAndView(ModelAndView modelAndView, DeviceClient deviceClient) {
        modelAndView.addObject("deviceClientForm", deviceClient);
        modelAndView.addObject("statusList", DeviceClientState.values());
        modelAndView.addObject("taskCmdList", BusinessTaskCmd.values());
    }

    protected void setClient(ClientVo clientVo, DeviceClient deviceClient) {
        copyProperties(clientVo, deviceClient);
        if (StringUtils.isNotBlank(clientVo.getState())) {
            deviceClient.setState(DeviceClientState.fromValue(clientVo.getState()));
        }
        if (StringUtils.isNotBlank(clientVo.getTaskCmd())) {
            deviceClient.setTaskCmd(BusinessTaskCmd.fromValue(clientVo.getTaskCmd()));
        }
    }

}
